<template>
  <div>
    <h2>home页</h2>
    <router-link to="/news">新闻</router-link>
    <button @click="addNum(5)">+</button>
    {{ $store.state.num }}
    <button @click="reduceNum(10)">-</button>
  </div>
</template>

<script>

export default {
  mounted () {
    // 调用一个action
    this.$store.dispatch('fetch_num', 10)
  },
  methods: {
    addNum (n) {
      // 调用对应mutation即可
      this.$store.commit('add_num', n)
    },
    reduceNum (n) {
      this.$store.commit('reduce_num', n)
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
